package com.parking.status.sync.netty.service;

import com.parking.status.sync.entity.*;
import com.parking.status.sync.netty.entity.*;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2015/9/25.
 */
@Component
public class RequestFactory {

    public RequestPre createRequestByCommand(CommandBase command) {
        //这里不在commandbase上create是为了降耦合

        RequestPre request = null;
        if (command instanceof CommandSyncParkingInfo) {
            CommandSyncParkingInfo cmd = (CommandSyncParkingInfo)command;
            request = new RequestSyncParkingInfo(
                    cmd.getSqo(),
                    cmd.getClientId(),
                    cmd.getTsn(),
                    cmd.getSim(),
                    cmd.getPsam(),
                    cmd.getSysVer(),
                    cmd.getAppVer(),
                    cmd.getUid(),
                    cmd.getBatchCode(),
                    cmd.getBizSn(),
                    cmd.getActTime(),
                    cmd.getParkingSpotId(),
                    cmd.getPlatformId(),
                    cmd.getTotBerthNum(),
                    cmd.getMonthlyBerthNum(),
                    cmd.getGuesBerthNum(),
                    cmd.getTotRemainNum(),
                    cmd.getMonthlyRemainNum(),
                    cmd.getGuestRemainNum()
            );

        } else if(command instanceof CommandParkingIn) {
            CommandParkingIn cmd = (CommandParkingIn)command;
            request = new RequestParkingIn(
                    cmd.getSqo(),
                    cmd.getClientId(),
                    cmd.getTsn(),
                    cmd.getSim(),
                    cmd.getPsam(),
                    cmd.getSysVer(),
                    cmd.getAppVer(),
                    cmd.getUid(),
                    cmd.getBusinessLogList(),
                    cmd.getBatchCode(),
                    cmd.getBizSn(),
                    cmd.getParkingSpotId(),
                    cmd.getPlatformId(),
                    cmd.getBerthId(),
                    cmd.getAddBerth(),
                    cmd.getBusinessType(),
                    cmd.getActType(),
                    cmd.getActTime(),
                    cmd.getCarNumber(),
                    cmd.getMonthlyCertNumber(),
                    cmd.getCarType(),
                    cmd.getTotRemainNum(),
                    cmd.getMonthlyRemainNum(),
                    cmd.getGuestRemainNum(),
                    cmd.getVoucherType(),
                    cmd.getVoucherNo()
            );
        } else if(command instanceof CommandParkingOut) {
            CommandParkingOut cmd = (CommandParkingOut)command;
            request = new RequestParkingOut(
                    cmd.getSqo(),
                    cmd.getClientId(),
                    cmd.getTsn(),
                    cmd.getSim(),
                    cmd.getPsam(),
                    cmd.getSysVer(),
                    cmd.getAppVer(),
                    cmd.getUid(),
                    cmd.getBusinessLogList(),
                    cmd.getBatchCode(),
                    cmd.getBizSn(),
                    cmd.getParkingSpotId(),
                    cmd.getPlatformId(),
                    cmd.getBerthId(),
                    cmd.getAddBerth(),
                    cmd.getBusinessType(),
                    cmd.getActType(),
                    cmd.getActTime(),
                    cmd.getCarNumber(),
                    cmd.getMonthlyCertNumber(),
                    cmd.getCarType(),
                    cmd.getTotRemainNum(),
                    cmd.getMonthlyRemainNum(),
                    cmd.getGuestRemainNum(),
                    cmd.getParkingTimeLength(),
                    cmd.getPayMoney(),
                    cmd.getPaymentType(),
                    cmd.getVoucherType(),
                    cmd.getVoucherNo()
            );
        } else if(command instanceof CommandParkingCheckin) {
            CommandParkingCheckin cmd = (CommandParkingCheckin)command;
            request = new RequestParkingCheckin(
                    cmd.getSqo(),
                    cmd.getClientId(),
                    cmd.getTsn(),
                    cmd.getSim(),
                    cmd.getPsam(),
                    cmd.getSysVer(),
                    cmd.getAppVer(),
                    cmd.getParkingSpotId(),
                    cmd.getPlatformId(),
                    cmd.getUid(),
                    cmd.getPwd(),
                    cmd.getLongi(),
                    cmd.getLati(),
                    cmd.getBatchCode(),
                    cmd.getName(),
                    cmd.getAddress(),
                    cmd.getOpentime(),
                    cmd.getPrice()
            );
        } else if(command instanceof CommandHeartBeat) {
            CommandHeartBeat cmd = (CommandHeartBeat)command;
            request = new RequestHeartBeat(
                    cmd.getSqo(),
                    cmd.getClientId(),
                    cmd.getTsn(),
                    cmd.getSim(),
                    cmd.getPsam(),
                    cmd.getSysVer(),
                    cmd.getAppVer(),
                    cmd.getParkingSpotId(),
                    cmd.getPlatformId(),
                    cmd.getWorkStat(),
                    cmd.getAlarmStat(),
                    cmd.getIpAddress(),
                    cmd.getMacAddress()
            );
        } else {}

        return request;
    }
}
